#!/bin/bash

# Create device files for Nvidia cards.
# Try this when cuda complains that the card is not found.

if ! modprobe nvidia
then 
  exit 1
fi

# Count the number of NVIDIA controllers found.
N3D=`/usr/bin/lspci | grep -i NVIDIA | grep "3D controller" | wc -l`
NVGA=`/usr/bin/lspci | grep -i NVIDIA | grep "VGA compatible controller" | wc -l`
# Create the devices with read permissions
# Major device is 195, minor device is the number of the card
N=$(( $N3D + $NVGA - 1 ))
for i in $(seq 0 $N); do
  mknod -m 666 /dev/nvidia$i c 195 $i
done

mknod -m 666 /dev/nvidiactl c 195 255
